package learn.ch1.join;

/**
 * @Description todo
 * @Author yusj
 * @Date 2021/12/14
 * @Version 1.0
 */
public class Thjoin01 implements Runnable{

    Thread priTh;

    public Thjoin01(Thread priTh){
        this.priTh=priTh;
    }

    @Override
    public void run() {
        try {
            priTh.join();
            System.out.println("-"+Thread.currentThread().getName()+" over ");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Thread priTh=Thread.currentThread();
        for(int i=0;i<10;i++){
            Thread currT=new Thread(new Thjoin01(priTh),"th"+i);
            currT.start();
            priTh=currT;
        }

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
